package com.cuz.hot100;

public class Q74SearchMatrix {
    public static boolean searchMatrix1(int[][] matrix, int target) {
        if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
            return false;
        }
        int x = 0;
        int colMax = matrix[0].length;
        int rowMax = matrix.length;
        int y = colMax - 1;
        while (x < rowMax && y >= 0) {
            int value = matrix[x][y];
            if (value == target) {
                return true;
            } else if (value > target) {
                y--;
            } else {
                x++;
            }
        }
        return false;
    }

}
